package com.text.day2_1.homework;

import java.math.BigDecimal;
import java.util.Random;

public class Hero {
    private String name;
    private double power;
    private double zhiLi;
    private double mingJie;

    public Hero() {
//        setPower();
    }

    public Hero(String name, double power, double zhiLi, double mingJie) {
        this.name = name;
        this.power = power;
        this.zhiLi = zhiLi;
        this.mingJie = mingJie;
    }

    public void attack() {
        Random random = new Random();
        double number = random.nextDouble() * 0.4 - 0.2 + 1;
        BigDecimal two = new BigDecimal(number * this.power);
        System.out.println("徒手攻击");
        System.out.println("攻击力：" + two.setScale(2,BigDecimal.ROUND_HALF_UP).doubleValue());
        //https://blog.csdn.net/weixin_45131680/article/details/132538179    double保留2位小数
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPower() {
        return power;
    }

    public void setPower(double power) {
        this.power = power;
    }

    public double getZhiLi() {
        return zhiLi;
    }

    public void setZhiLi(double zhiLi) {
        this.zhiLi = zhiLi;
    }

    public double getMingJie() {
        return mingJie;
    }

    public void setMingJie(double mingJie) {
        this.mingJie = mingJie;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", power=" + power +
                ", zhiLi=" + zhiLi +
                ", mingJie=" + mingJie +
                '}';
    }
}
